#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

pthread_cond_t cond;
pthread_mutex_t lock;
void* r1(void* args)
{
  while(1)
  {
    pthread_cond_wait(&cond, &lock);
    printf("%s活动...\n", (char*)args);
  }
  return NULL;
}
//线程2控制线程1运行步调
void* r2(void* args)
{
  while(1)
  {
    pthread_cond_signal(&cond);
    sleep(1);
  }
  return NULL;
}
int main()
{
  pthread_mutex_init(&lock, NULL);
  pthread_cond_init(&cond, NULL);
  pthread_t tid1, tid2;
  pthread_create(&tid1, NULL, r1, (void*)"pthread1");
  pthread_create(&tid2, NULL, r2, (void*)"pthread2");
  
  pthread_join(tid1, NULL);
  pthread_join(tid2, NULL);
  pthread_cond_destroy(&cond);
  pthread_mutex_destroy(&lock);
  return 0;
}
